// pages/perCenter/bankList/bankList.js

var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banks: [],
    winHeight: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winHeight: res.windowHeight
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    this.getData(that);
  },
  getData: function (that) {

    util.request(api.BankSerach, { token: wx.getStorageSync("token") }).then(function (res) {
      if (res.code == '200') {
        console.log(res.datas);
        that.setData({
          banks: res.datas
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  fnToNewAddr: function () {
    wx.navigateTo({
      url: '/pages/perCenter/bankListW/bankListW',
    })
  },
  toBankDetail:function(e){
    var id = e.currentTarget.dataset.id
    var bankName = e.currentTarget.dataset.bankname
    var accountNumber = e.currentTarget.dataset.accountnumber
    var accountName = e.currentTarget.dataset.accountname
    var bankOfDeposit = e.currentTarget.dataset.bankofdeposit
    var isDefault = e.currentTarget.dataset.isdefault
    var bankCode = e.currentTarget.dataset.bankcode
    var logoUrl = e.currentTarget.dataset.logourl
    var cardType = e.currentTarget.dataset.cardtype
    wx.navigateTo({
      url: '/pages/perCenter/bankListW/bankListW?id=' + id + "&bankName=" + bankName + "&accountNumber=" + accountNumber + "&accountName=" + accountName + "&bankOfDeposit=" + bankOfDeposit + "&bankCode=" + bankCode + "&logoUrl=" + logoUrl + "&cardType=" + cardType + "&isDefault=" + isDefault
    })
  },
  del:function(e){
    let that=this
    var id = e.currentTarget.dataset.id
    var obj=new Object();
    obj.id=id;
    wx.showModal({
      title: '解除绑定',
      content: '',
      success(options) {
        if (options.confirm) {
          util.request(api.BankOper, { "bankCardStr": obj, token: wx.getStorageSync('token'),type:'del'}).then(function (res) {
            if (res.code === "200") {
              that.getData(that)
            }
          });
        }
      }
    })
  }
})